﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class manage_public_page_notice_add : System.Web.UI.Page
{
    string[] arrField = {"id", "title", "contents"};
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {       
            SqlTransaction myTrans = DataBaseOperate_SQLServer.objConnection.BeginTransaction();
            SqlCommand objCommand = new SqlCommand();
            objCommand.Connection = DataBaseOperate_SQLServer.objConnection;
            objCommand.Transaction = myTrans;
            try
            {
                System.Text.StringBuilder sbstr = new System.Text.StringBuilder(200);

                sbstr.Append("insert into t_notice(");
                for (int i = 1; i < arrField.Length; i++)
                {
                    sbstr.Append(arrField[i]);
                    if (i < arrField.Length - 1)
                    {
                        sbstr.Append(",");
                    }
                }
                sbstr.Append(") values (");
                for (int i = 1; i < arrField.Length; i++)
                {
                    sbstr.Append("@");
                    sbstr.Append(arrField[i]);
                    if (i < arrField.Length - 1)
                    {
                        sbstr.Append(",");
                    }
                }
                sbstr.Append(")");
                objCommand.CommandText = sbstr.ToString();
                String title = texTitle.Text;
                String contents = texContents.Text;
                objCommand.Parameters.Add("@title", title);
                objCommand.Parameters.Add("@contents", contents);
                //DataBaseOperate_SQLServer.ExecUpdate(objCommand);
                objCommand.ExecuteNonQuery();
                myTrans.Commit();                
            }
            catch (Exception ex)
            {
                Log.Record(ex);
                myTrans.Rollback();
            }
            finally
            {
                Response.Redirect("notice_list.aspx");
            }
        }

}
